import time
from public.action import *
from public.business import *
from public.testData import *
from public.tools import *

testCase = "dbshopST011_添加商品"


# 1.点击销售管理退货管理。
# 2.点击退货方式，选择框选择“退货到账户余额”点击“搜索”按钮。

# # 前端退货申请
firefox=openBrowser(url)
DBshopLogin(firefox,userName,password)
# 我的订单
firefox.find_element_by_link_text('我的订单').click()
firefox.find_element_by_link_text('退货申请').click()
firefox.find_element_by_link_text('点此申请退货').click()

# 读取order1中的编号
rootPath=get_pro_rootpath() #获取项目的绝对路径
filePath=rootPath+r'\public\order1.txt' #拼接文件路径
orderNo=readFile(filePath) #读取文件中的订单编号

# 填写退货信息页面
firefox.find_element_by_xpath('//input[@name="order_sn"]').send_keys(orderNo)
firefox.find_element_by_xpath('//button[@id="search-order"]').click()
time.sleep(2)
firefox.find_element_by_id('refund_info').send_keys('不要了退货')
firefox.find_element_by_xpath('//button[text()="申请退货"]').click()
time.sleep(2)
firefox.switch_to.alert.accept()



# 后台退货
firefox.get(urlAdmin)
DBshopLoginAdmin(firefox)

DBshopEnterMenu2(firefox,'销售管理','退货管理')
firefox.find_element_by_xpath('//input[@name="order_sn"]').send_keys(orderNo)
firefox.find_element_by_xpath('//option[text()="退款到账户余额"]').click()
firefox.find_element_by_xpath('//button[contains(text(),"搜索")]').click()
firefox.find_element_by_link_text('处理退货').click()
firefox.find_element_by_xpath('//option[text()="同意退货"]').click()
firefox.find_element_by_xpath('//input[@id="refund_price"]').clear()

firefox.find_element_by_xpath('//input[@id="refund_price"]').send_keys('2199')
firefox.find_element_by_id('re_refund_info').send_keys('同意退货')
firefox.find_element_by_xpath('//button[text()="提交处理结果"]').click()


# 前台查看
firefox.get(url)
time.sleep(2)

firefox.find_element_by_link_text('我的订单').click()
firefox.find_element_by_link_text('退货申请').click()
# firefox.find_element_by_xpath('//input[@name="search_content"]').send_keys(orderNo)
# firefox.find_element_by_xpath('//button[text()="搜索"]').click()

state=firefox.find_element_by_xpath('//td[contains(.,"%s")]/following-sibling::td[3]'%orderNo).text
yuqi=' 	退款成功'

# 断言
try:
    state == yuqi
    writeLog("%s 测试通过"%testCase)
except:
    writeLog("%s 测试失败" % testCase)
    getPhoto(firefox)
firefox.quit()
